package p2p.model.vo
{
	[Bindable]
	public class DescriptorVO
	{
		public static const DEFAULT_PACKET_SIZE_BYTES:int = 65535;
		
		public var id:uint;
		public var size:Number = 0;
		public var packetSize:Number = 0;
		public var filename:String;		
		public var senderName:String;
		public var bytesLoaded:uint = 0; // count of loaded bytes
		public var startChunkIndex:int;
		public var endChunkIndex:int;
		
		public function DescriptorVO()
		{
			id = Math.floor(Math.random() * 1000000000 );
			packetSize = DEFAULT_PACKET_SIZE_BYTES;
		}
		
		public function get packetLength():int
		{
			return Math.floor(size / packetSize) + 1;	// last packet is not filled completely
		}
		
		public static function convert(target:Object):DescriptorVO
		{
			var descriptor:DescriptorVO = new DescriptorVO();
			
			descriptor.id = target.id;
			descriptor.size = target.size;
			descriptor.packetSize = target.packetSize;
			descriptor.filename = target.filename;
			descriptor.senderName = target.senderName;
			descriptor.bytesLoaded = target.bytesLoaded;
			descriptor.startChunkIndex = target.startChunkIndex;
			descriptor.endChunkIndex = target.endChunkIndex;
			
			return descriptor;
		}
	}
}